package com.dyzs.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.widget.Toast;


public class ToolUtils {

	
	public static boolean checkBrowser(Context context,String packageName) {   
 	    if (packageName == null || "".equals(packageName))   
 	        return false;   
 	    try {   
 	        ApplicationInfo info = context.getPackageManager().getApplicationInfo(   
 	                packageName, PackageManager.GET_UNINSTALLED_PACKAGES);   
 	        return true;   
 	    } catch (NameNotFoundException e) {   
 	        return false;   
 	    }   
 	}  
 	
 	
	public static Intent starBrowser(String packageName,String activity) {   
		Intent t = new Intent();   
		t.setClassName(packageName,activity);
		return t;
 	} 
	
	
	
	public static void toastText(Context context,String message) {
		Toast.makeText(context,message,Toast.LENGTH_SHORT).show();
	}
	
	
	public static long getBetweenDays(String t1,int t2) throws ParseException{
		DateFormat formatObj=new SimpleDateFormat("yyyy-MM-dd"); 		
		long k1=formatObj.parse(new Date().toLocaleString()).getTime();
		long k2=formatObj.parse(t1.substring(0,10)).getTime()+ t2 * 24 * 60 * 60 * 1000;
		return k1-k2;		
	} 
	
	public static  boolean isPhone(String mobiles){
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();		
	}
	
	public static  boolean isTel(String mobiles){
		 Pattern p = Pattern.compile( "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1} \\d{1}-?\\d{8}$)|(^0[3-9]{1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-?\\d{7,8}-(\\d{1,4})$))");
		 Matcher m = p.matcher(mobiles);
		return m.matches();		
	}
}
